package com.cxs.xiaomi.dao.impl;

import com.cxs.xiaomi.dao.OrderDao;
import com.cxs.xiaomi.domain.Order;
import cxs.handler.impl.ResultHandlerAsBeanImpl;
import cxs.handler.impl.ResultHandlerAsListImpl;
import cxs.templete.JdbcTemplete;
import cxs.utils.JdbcUtil;

import java.util.List;

/*
 * @Author:cxs
 * @Date:2021/9/17  9:55
 * @Version 1.0
 * @Motto:放下杂念,只为迎接明天更好的自己
 * */
public class OrderDaoImpl implements OrderDao {
    @Override
    public int insert(Order order) {
        String sql = "insert into tb_order values(?,?,?,?,?,?)";
        Object[] arrs = {order.getId(), order.getUid(), order.getMoney(), order.getStatus(), order.getTime(), order.getAid()};
        return JdbcTemplete.DMLTemplete(sql, arrs);
    }

    @Override
    public List<Order> selectAllByUid(Integer uid) {
        String sql = "select * from tb_order where uid = ?";
        return JdbcTemplete.DQLTemplete(sql,new ResultHandlerAsListImpl<>(Order.class),uid);
    }

    @Override
    public Order selectById(String oid) {
        String sql = "select * from tb_order where id = ?";
        return JdbcTemplete.DQLTemplete(sql,new ResultHandlerAsBeanImpl<>(Order.class),oid);
    }

    @Override
    public int updateStateById(String oid, String state) {
        String sql = "update tb_order set status = ? where id = ?";
        return JdbcTemplete.DMLTemplete(sql,state,oid);
    }

    @Override
    public List<Order> selectAll() {
        String sql = "select * from tb_order";
        return JdbcTemplete.DQLTemplete(sql,new ResultHandlerAsListImpl<>(Order.class));
    }

    @Override
    public List<Order> selectByCondition(String condition, List params) {
        String sql = "select * from tb_order" + condition;
        return JdbcTemplete.DQLTemplete(sql,new ResultHandlerAsListImpl<>(Order.class),params.toArray());
    }
}
